package au.com.handsunited.model.notices;

import java.io.Serializable;
import java.util.SortedSet;
import java.util.TreeSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.com.handsunited.model.MotherOfAllEntities;

/**
 * @author Arun Chandrasekhar
 *
 */
public class NoticeBoard extends MotherOfAllEntities implements Serializable{


	private SortedSet<Notice> notices;

	
	private static Logger logger = LoggerFactory.getLogger(NoticeBoard.class);

	
	public NoticeBoard() {
		super();
		notices = new TreeSet<Notice>();
	}
	
	public void addNotice(Notice notice) {
		notice.setNoticeBoard(this);
		if (notices == null) {
			notices = new TreeSet<Notice>();
		}
		notices.add(notice);
	}

	
	public SortedSet<Notice> getActiveNotices() {
		SortedSet<Notice> activeNotices = new TreeSet<Notice>();
		
		for (Notice notice : getNotices()) {
			if (notice.getStatus() == NoticeStatus.ACTIVE) {
				activeNotices.add(notice);
			}
		}
		
		return activeNotices;
	}

	public int getNoOfActiveNotices() {
		return getActiveNotices().size();
	}
	
	public SortedSet<Notice> getExpiredNotices() {
		SortedSet<Notice> expiredNotices = new TreeSet<Notice>();
		
		for (Notice notice : getNotices()) {
			if (notice.getStatus() == NoticeStatus.EXPIRED) {
				expiredNotices.add(notice);
			}
		}
		
		return expiredNotices;
	}
	
	public int getNoOfExpiredNotices() {
		return getExpiredNotices().size();
	}
	
	public SortedSet<Notice> getNotices() {
		if (notices == null) {
			notices = new TreeSet<Notice>();
		}
		return notices;
	}
	
	public int getNoOfNotices() {
		return notices.size();
	}

	public void setNotices(SortedSet<Notice> notices) {
		this.notices = notices;
	}

}
